JAR_NAME="tool-demo-0.0.1-SNAPSHOT.jar"
MAIN_CLASS="com.example.tooldemo.ToolDemoApplication"
EMPTY_PID=0
PID=${EMPTY_PID}

function get_pid()
{
    server_status=$(pgrep -f "${MAIN_CLASS}")
    echo "--> server_status: $server_status"
    #PID=$(echo "$server_status" | awk '{ print $2; exit; }')
    PID=$server_status
    echo "1-->PID:$PID"
    if [[ -z "${PID}" ]]
    then
        PID=${EMPTY_PID}
    fi
    echo "2-->PID:$PID"
}

java_opts="-Xms1g -Xmx1g -XX:NewRatio=3 -XX:ParallelGCThreads=4
                -XX:+PrintGC
                 -XX:+PrintGCDateStamps
                 -XX:+PrintGCDetails
                 -XX:GCLogFileSize=50M
                 -XX:NumberOfGCLogFiles=10
                 -XX:+UseGCLogFileRotation
                 -XX:+HeapDumpOnOutOfMemoryError
                 -XX:HeapDumpPath=/root/gitee_go/deploy
                 -Xloggc:/root/gitee_go/deploy/gc.log"

echo "=========== start_service ==========="
get_pid
if [[ ${PID} -ne ${EMPTY_PID} ]]
then
    kill -9 ${PID}
    echo "======= kill_service, pid=${PID} ======="
fi
echo "===start sevice==="

nohup java -jar ${JAR_NAME} ${MAIN_CLASS} > output.log &

